import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:love_app/common/su.dart';
import 'package:love_app/providers/love_record_item_provider.dart';
import 'package:love_app/routes/application.dart';
import 'package:provider/provider.dart';

//恋爱记录上面四个图标
class CenterItem extends StatefulWidget {
  @override
  _CenterItemState createState() => _CenterItemState();
}

class _CenterItemState extends State<CenterItem> {
  BuildContext _context;
  // LoveRecordItemProvider _loveRecordItemProvider;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Su.suPrints("重构了");
    _context = context;
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(
        top: Su().h(42),
        bottom: Su().h(40),
      ),
      child: _allItem(),
    );
  }

  // 所有的item
  Row _allItem() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: <Widget>[
        _loveNotes(),
        _loveDay(),
        _loveImages(),
        _loveBaoXian(),
      ],
    );
  }

  // 恋爱笔记
  Widget _loveNotes() {
    return InkWell(
      onTap: () {},
      child: Column(
        children: <Widget>[
          _imageItemConsumer("images/love_record/love_notes.png"),
          _textChild('恋爱笔记'),
        ],
      ),
    );
  }

  // 恋爱笔记
  Widget _loveDay() {
    return InkWell(
      onTap: () {},
      child: Column(
        children: <Widget>[
          _imageItemConsumer("images/love_record/love_data.png"),
          _textChild('恋爱纪念日'),
        ],
      ),
    );
  }

  // 恋爱相册
  Widget _loveImages() {
    return InkWell(
      onTap: () {
        Application.router.navigateTo(_context, "/loveGralley", transition: TransitionType.inFromLeft);
      },
      child: Column(
        children: <Widget>[
          _imageItemConsumer("images/love_record/love_images.png"),
          _textChild('恋爱相册'),
        ],
      ),
    );
  }

  // 恋爱保险
  Widget _loveBaoXian() {
    return InkWell(
      onTap: () {},
      child: Column(
        children: <Widget>[
          _imageItemConsumer("images/love_record/love_baoxian.png"),
          _textChild('恋爱基金'),
        ],
      ),
    );
  }

  Widget _imageItemConsumer(String imagePath) {
    return Consumer<LoveRecordItemProvider>(
      builder: (context, LoveRecordItemProvider loveRecordItemProvider, child) {
        double size = loveRecordItemProvider.imageSize == null ? Su().w(94) : loveRecordItemProvider.imageSize;
        return Image.asset(
          imagePath,
          width: size,
          height: size,
        );
      },
    );
  }

  // 文字样式
  Widget _textChild(String text) {
    Widget widgetNull = Container();
    Widget widgetTrue = Container(
      padding: EdgeInsets.only(
        top: Su().h(3),
      ),
      child: Text(
        text,
        style: Su().textStyle(Color.fromRGBO(128, 128, 128, 1), 22),
      ),
    );
    // 不用整个页面重新build, 真是太牛逼了
    return Consumer<LoveRecordItemProvider>(
      builder: (context, LoveRecordItemProvider loveRecordItemProvider, child) {
        return loveRecordItemProvider.opacityData == 0.0
            ? widgetNull
            : widgetTrue;
      },
    );
  }
}
